/* * Copyright (C) 2021 Huawei Device Co., Ltd.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.zhouyou.http.model.utils;

import org.junit.Test;

import static org.junit.Assert.*;

public class MD5Test {

    @Test
    public void encode() {
        String empty = MD5.encode("");
        assertTrue("Is the MD5 result correct", "d41d8cd98f00b204e9800998ecf8427e".equals(empty));
        String amd5 = MD5.encode("a");
        assertTrue(" A md5 value correct", "0cc175b9c0f1b6a831c399e269772661".equals(amd5));
        String abcmd5 = MD5.encode("abc");
        assertTrue(" abc md5 value  correct", "900150983cd24fb0d6963f7d28e17f72".equals(abcmd5));


    }

    @Test
    public void string2MD5() {
        String result = MD5.string2MD5("123");
        assertTrue(" Whether the length of result is 32 bits", result.length() == 32);

    }

    @Test
    public void encrypt() {
        String result = MD5.encrypt("123");
        assertTrue(" 加密后的字符串，不支持此类字符集合返回null", result != null);
    }

}